import { http } from '@renderer/plugins/axios'
import { ref } from 'vue'
import useUtil from './useUtil'
import { ElMessage } from 'element-plus'

export default () => {
  const expoetList = ref<ApiPage<ExportModel>>()
  const getExportRecord = useUtil().request(async (data) => {
    try {
      expoetList.value = await http.request({
        url: '/gui/getExportRecord',
        method: 'POST',
        data,
      })
    } catch (error) {
      console.log(error)
    }
  })
  const getProjectBillList = useUtil().request(async () => {
    const billList = await http.request<ApiPage<projectBillModel>>({
      url: '/getProjectBillList',
      method: 'GET',
      params: {
        page: 1,
        limit: 200,
        keywords: '',
        date: '',
        work_status: '-1',
        clear_account: '-1',
        void_check: '-1',
      },
    })
    return billList
  })
  const getBillAccountList = useUtil().request(async () => {
    const accountList = await http.request<AccountModel[]>({
      url: '/getBillAccountList',
      method: 'GET',
    })
    return accountList
  })
  const accountExportData = useUtil().request(async (data: any) => {
    try {
      await http.request({
        url: '/accountExportData',
        method: 'POST',
        data,
      })
      ElMessage({ type: 'success', message: '该数据已成功发送至您的邮箱，请注意查收！' })
    } catch (error) {
      console.log(error)
    }
  })
  const exportData = useUtil().request(async (data: any) => {
    try {
      await http.request({
        url: '/exportData',
        method: 'POST',
        data,
      })
      ElMessage({ type: 'success', message: '该数据已成功发送至您的邮箱，请注意查收！' })
    } catch (error) {
      console.log(error)
    }
  })
  const stashStockExport = useUtil().request(async (data: any) => {
    try {
      await http.request({
        url: '/stashStockExport',
        method: 'POST',
        data,
      })
      ElMessage({ type: 'success', message: '该数据已成功发送至您的邮箱，请注意查收！' })
    } catch (error) {
      console.log(error)
    }
  })
  return {
    getExportRecord,
    expoetList,
    getProjectBillList,
    getBillAccountList,
    accountExportData,
    exportData,
    stashStockExport,
  }
}
